package seeders

import (
	"fmt"

	"gorm.io/gorm"

	"github.com/runningwater/gohub/database/factories"
	"github.com/runningwater/gohub/pkg/console"
	"github.com/runningwater/gohub/pkg/logger"
	"github.com/runningwater/gohub/pkg/seed"
)

func init() {
	// 添加 Seeder
	seed.Add("{{StructNamePlural}}TableSeeder", func(db *gorm.DB) {
        // 创建 10 个用户对象
        {{VariableNamePlural}} := factories.Make{{StructNamePlural}}(10)

        // 批量插入到数据库
        result := db.Table("{{TableName}}").Create(&{{VariableNamePlural}})

        if err := result.Error; err != nil {
            logger.LogIf(err)
            return
        }

        // 打印成功信息
        console.Success(fmt.Sprintf("Table [%v] %v rows seeded", result.Statement.Table, result.RowsAffected))
	})
}
